package light.head.controller.oa;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import light.head.constant.Parm;
import light.head.constant.Url;
import light.head.dao.oa.ReimburseDAO;
import light.head.dao.sys.OrganDAO;
import light.head.enm.RESULT;
import light.head.framework.base.SupporterController;
import light.head.framework.entity.PageBean;
import light.head.model.Organ;
import light.head.model.ReimburseItem;
@Controller
@RequestMapping(value = Url.C_RREIMBURSECENSUS)
public class ReimburseCensusController extends SupporterController{
	
	private ReimburseDAO reDAO;
	private OrganDAO organDAO;
	
	@RequestMapping(value = Url.INIT)
	public ModelAndView init(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Integer> o = organDAO.getSonCodeList(cu_organCode(request));
		List<Organ> organ = organDAO.findOcs(o);
		request.setAttribute(Parm.ORGAN, organ);
		return new ModelAndView(Url.REIMBURSE_CENSUS_INIT);
	}
	
	@RequestMapping(value = Url.QUERY)
	public ModelAndView query(HttpServletRequest request, HttpServletResponse response) throws Exception {
		PageBean pb = createPageBean(request);
		Map<String, String> map = createQueryMapByParmName(request, Parm.DELETED, Parm.TIME1, Parm.TITLE, Parm.TIME2, Parm.PROJECT,Parm.OC,Parm.CN,Parm.PASS,Parm.SUC);
		
			// 获取根机构配置的物品申请流程节点
			if (reDAO.findCode(organDAO.getSonCodeList(cu_organCode(request)), map, pb) == RESULT.SUCCESS) {
				// 讲对应的审核状态放到对应的
				ReimburseItem ri = null;
				ReimburseItem re = null;
				
				for (Object o : pb.getResultList()) {
					ri = (ReimburseItem) o;
					Double total = (double) 0;
					for (Object oi : pb.getResultList()) {
						re = (ReimburseItem) oi;
						if (ri.getRcc() == re.getRcc())
							total = total + ri.getAmount();
						}	
					}
			}
		request.setAttribute(Parm.PAGE_BEAN, pb);
		return new ModelAndView(Url.REIMBURSE_CENSUS_LIST);
	}
	
	@Autowired
	public void setReDAO(ReimburseDAO reDAO) {
		this.reDAO = reDAO;
	}
	@Autowired
	public void setOrganDAO(OrganDAO organDAO) {
		this.organDAO = organDAO;
	}


}
